#include "main/utils.h"
#include "lib/binary_tree.h"
using namespace std;

vector<int> printRightView(BinaryTreeNode* root) {
  if (!root)
    return {};
  deque<BinaryTreeNode*> node_deque1;
  deque<BinaryTreeNode*> node_deque2;
  node_deque1.push_back(root);
  vector<int> ret;
  while (!node_deque1.empty()) {
    auto front_node = node_deque1.front();
    node_deque1.pop_front();
    if (front_node->left)
      node_deque2.push_back(front_node->left);
    if (front_node->right)
      node_deque2.push_back(front_node->right);
    if (node_deque1.empty()) {
      ret.push_back(front_node->value);
      swap(node_deque1, node_deque2);
    }
  }
  return ret;
}

int main() {
  vector<int> vec = {8, 6, 10, 5, 7};
  BinaryTreeNode* root = CreateBinaryTree(vec);
  vector<int> ret = printRightView(root);
  printVec("RightView", ret);

  return 0;
}
